package com.modifiertech.lineage.network;

import com.modifiertech.lineage.Lineage;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

/**服务端通知客户端的
 *
 * 技能cd 消息
 *
 * @description: default
 * @author: saliencemn
 * @mail: hackingmu@outlook.com
 * @date: 2024/9/14 23:29
 */
public class MessageClientSkillCD implements IMessage, IMessageHandler<MessageClientSkillCD,IMessage> {
    private NBTTagCompound nbtTagCompound=new NBTTagCompound();

    @Override
    public void fromBytes(ByteBuf byteBuf) {
        nbtTagCompound= ByteBufUtils.readTag(byteBuf);
    }

    @Override
    public void toBytes(ByteBuf byteBuf) {
        ByteBufUtils.writeTag(byteBuf,nbtTagCompound);
    }

    @Override
    public IMessage onMessage(MessageClientSkillCD messageClientSkillCD, MessageContext messageContext) {
        //收到cd通知消息后,覆盖到客户端playerData 中
        Minecraft.getMinecraft().addScheduledTask(() -> {
            Lineage.proxy.handleMessageClientSkillCD(messageClientSkillCD, messageContext);
        });
        return null;
    }
    //构造客户端消息内容nbt
    public synchronized MessageClientSkillCD write(String skillName,long cdavailable){
        //INIT
        this.getNbtTagCompound().setString("skillName",skillName);
        this.getNbtTagCompound().setLong("cdavailable",cdavailable);
        return this;
    }

    public NBTTagCompound getNbtTagCompound() {
        return nbtTagCompound;
    }

    public void setNbtTagCompound(NBTTagCompound nbtTagCompound) {
        this.nbtTagCompound = nbtTagCompound;
    }
}
